﻿using UnityEngine;
using System.Collections;

public class Bean : MonoBehaviour
{

    public float qSpeed;
    public Transform child;
    private Obstacle obstacle;

    // Use this for initialization
    void Start ()
    {
        GameController.gameController.AddBean ();
        Destroy (this.gameObject.GetComponent<Rigidbody> (), 0.1f);
    }
    
    // Update is called once per frame
    void Update ()
    {
        child.Rotate (qSpeed * Time.deltaTime, qSpeed * Time.deltaTime, qSpeed * Time.deltaTime);
    }

    //判断是否需要销毁
    void OnTriggerEnter (Collider moveTarget)
    {
        if (moveTarget != null)
        {
            obstacle = moveTarget.gameObject.GetComponent<Obstacle> ();
            if (obstacle != null)
            {
                GameController.gameController.DestroyBean ();
                Destroy (this.gameObject);
            }
        }
    }

}
